////显示外贸价格单弹窗 
	 jQuery('#queryforeignQuote').on("click",function(){
		 jQuery("#foreignQuoteModal").modal('show');
	 });
	 
	 //外贸单table
	 var foreignQuoteData={};
	 var foreignQuoteTable;
	 foreignQuoteData.key='';
	 foreignQuoteData.auditState='通过';
	 jQuery(document).ready(function () {
		 foreignQuoteTable = jQuery('#foreignQuoteTable').DataTable({
			 "serverSide": true,
	            "ordering": false,
	            "ajax": {
	                "dataType": "json",
	                "type": "get",
	                "cache": false,
	                "url":window.rootPath+ '/ui/bid/getAduitForeignQuote',
	                "data": function (d) {
	                    return $.extend({}, d, foreignQuoteData);
	                }
	            },
	            columns: [
	                {
	                	data: null,
	                	defaultContent: ""
	                },
	                {
	                    data: null,
	                    defaultContent: "",
	                    render: function (data, type, full, meta) {
	                    	var id=data.id
	    	            	var operate ='<input type="checkbox" class="checkchild">';
	    	            	return operate;

	                    }
	                },
	                {
	                	data: 'name'            	
	                },
	                {
	                	data: 'auditState',
	                    render: function (data, type, full, meta) {
	                     	var dOut;
	                     	 if(data=='审批中'){
	                     		dOut = '<td class="center" ><span class="badge label-pill label-primary">审批中</span></td>';
	                     	}
	                     	else if(data=='驳回'){
	                     		dOut = '<td class="center" ><span class="badge label-pill label-danger">驳回</span></td>';
	                     	}
	                     	else if(data=='通过'){
	                     		dOut = '<td class="center" ><span class="badge label-pill label-success">通过</span></td>';
	                     	}
	                     	else  if(data=='未提交'){
	                     		dOut = '<td class="center" ><span class="badge label-pill label-default">未提交</span></td>';
	                     	}
	                    	else  if(data=='已提交'){
	                     		dOut = '<td class="center" ><span class="badge label-pill label-warning">已提交</span></td>';
	                     	}
	     	            	return dOut;
	                     }
	                },
	                {
	                    data: 'sum'
	                },
	                {
	                	data: 'createTime',
	                		render : function(data,type, full,meta) {
	    						if (data) 
	    						{
	    							return moment(data).format("YYYY-MM-DD");
	    						}
	                	}
	                },
	                {
	                	data: 'memo'
	                }
	                
	                ],
	            "drawCallback": function (oSettings) {
	                var k = 0;
	                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
	                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
	                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
	                    k++;
	                }

	            }
	     });
	     
	 });
	 
	//查询按钮
	 jQuery('.foreignsearchBtn').on('click',function(){
		      foreignQuoteData.key=jQuery("#foreignkeyword").val();
		      foreignQuoteTable.draw();
	      });
		//撤消查询
	 jQuery('.foreignresetBtn').on('click',function(){
	     jQuery('#foreignkeyword').val('');
	     foreignQuoteData.key='';
	     foreignQuoteTable.draw();
	 });
	 
	 ////点击编辑外贸价格单tab
	 jQuery("#t3").on('click', function(){
		 var bidId= jQuery("#bidId").val();
         var url=window.rootPath+"/ui/bid/getBid"+"?bidId="+bidId;
         jQuery.ajax({
				type : 'get',
				url : encodeURI(url),
				dataType : 'json',
				contentType : 'application/json;charset=utf-8',
				success : function(data) {
					if(data==null){
						jQuery("#foreignId").val(data.foreign.id);
						jQuery("#foreignName").val(data.foreign.name);
						jQuery("#foreignmemo").val(data.foreign.memo);
						jQuery("#currency").val(data.foreign.currency);
						var costSum=data.foreign.costSum;
						jQuery("#costSumf").val(data.foreign.costSum);
						jQuery("#productSum").val(data.foreign.productSum);
						jQuery("#productRatio").val(data.foreign.productRatio);
						jQuery("#productOff").val(data.foreign.productOff);
						jQuery("#exportWay").val(data.foreign.exportWay);
						jQuery("#packPrice").val(data.foreign.packPrice);
						jQuery("#packRatio").val(data.foreign.packRatio);
						jQuery("#packOff").val(data.foreign.packOff);
						jQuery("#sumf").val(data.foreign.sum);
						var foreignquoteId=data.foreign.id;
						foreignmainDeviceData.quoteForeignId=foreignquoteId;
						foreignmainDeviceTable.draw();
						foreignserverData.quoteForeignId=foreignquoteId;
						foreignserverTable.draw();
						////显示外贸报价单的附件数量
						if(foreignquoteId!=undefined){
							showANum(foreignquoteId,'外贸价格单附件','foreign-quote-ANum');
						}
					}
			   		
				}
			}); 
	 });
	 
	 ///引入外贸价格单
	 jQuery('#pull-foreignquote').on('click',function(){
		 var selects=getSelect("#foreignQuoteTable",1);
	   	   if(selects.length>1){
	   		   $.springLemonDialog({
	   		         content: '只能操作一条记录',// 确认文本
	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	   		             $(this).closeDialog(modal);
	   		         }
	   		   }); 
	   	   }
	   	   else if(selects.length==0){
	   		   $.springLemonDialog({
	   		         content: '请选择要操作的记录',// 确认文本
	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	   		             $(this).closeDialog(modal);
	   		         }
	   		   }); 
	   	   }else if(selects.length==1){
	   		    jQuery("#foreignId").val(selects[0].id);
		   		jQuery("#foreignName").val(selects[0].name);
		   		jQuery("#foreignmemo").val(selects[0].memo);
		   		jQuery("#currency").val(selects[0].currency);
		   		jQuery("#productSum").val(selects[0].productSum);
		   		jQuery("#productRatio").val(selects[0].productRatio);
		   		jQuery("#productOff").val(selects[0].productOff);
		   		jQuery("#exportWay").val(selects[0].exportWay);
		   		jQuery("#packPrice").val(selects[0].packPrice);
		   		jQuery("#packRatio").val(selects[0].packRatio);
		   		jQuery("#packOff").val(selects[0].packOff);
		   		jQuery("#foreignSum").val(selects[0].sum);
		   		var foreignquoteId=selects[0].id;
		   		foreignmainDeviceData.quoteForeignId=foreignquoteId;
		   		foreignmainDeviceTable.draw();
		   		foreignserverData.quoteForeignId=foreignquoteId;
		   		foreignserverTable.draw()
		   		showANum(foreignquoteId,'外贸价格单附件','foreign-quote-ANum');
		   		jQuery("#foreignQuoteModal").modal('hide'); 		
	   	   }  
	 })
	 // 新增投标，引入价格单的下载附件
	 jQuery(".downloadforeign").on('click', function() {
		var foreignId = jQuery("#foreignId").val();
			filedown(foreignId, '外贸价格单附件',0);
	 });
	 
	 ////主机设备
	 var foreignmainDeviceData = {};
		var foreignmainDeviceTable;
		jQuery(document).ready(function() {
			foreignmainDeviceTable = jQuery('#foreignmainDeviceTable').DataTable({
				"serverSide": true,
	            "ordering": false,
	            "ajax": {
	                "dataType": "json",
	                "type": "get",
	                "cache": false,
	                "url":window.rootPath+ '/ui/quote-foreign/getMainpage',
	                "data": function (d) {
	                    return $.extend({}, d, foreignmainDeviceData);
	                }
	            },
	            columns: [ {
					data : null,
					defaultContent : ""
				}, 
				{
					data : 'productName'
				}, 
				{
					data : 'productType'
				}, 
				{
					data : 'productModel'
				},
				{
					data : null,
					render : function(data,type, full, meta) {
						var dOut;
						if (data.isInventory == "1") {
						 dOut = '<td class="center" ><span class="badge label-pill label-success">已降库</span></td>';
								} 
						else {
						 dOut = '<td class="center" ><span class="badge label-pill label-danger">未降库</span></td>';
								}
						return dOut;
							}
				},
				{
					data : 'number'
				},
				{
					data:'unit'
				}, 
				{
					data : 'costPrice'
				},
				{
					data : 'unitPrice'
				}, {
					data : 'power'
				}, {
					data : 'flowMaterial'
				}, {
					data : 'transMedia'
				}, {
					data : 'viscosity'
				}, {
					data : 'flux'
				}, {
					data : 'pumpLift'
				}, {
					data : 'temperature'
				}, {
					data : 'proportion'
				}, {
					data : 'inPressure'
				}, {
					data : 'effectiveNPSHA'
				}, {
					data : 'mustMPSHA'
				} ],
	            "drawCallback": function (oSettings) {
	                var k = 0;
	                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
	                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
	                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
	                    k++;
	                }

	            }
	        });
	});
	////其他设备	
		 var foreignserverData = {};
		 var foreignserverTable;
			jQuery(document).ready(function() {
				foreignserverTable = jQuery('#foreignotherTable').DataTable({
					"serverSide": true,
		            "ordering": false,
		            "ajax": {
		                "dataType": "json",
		                "type": "get",
		                "cache": false,
		                "url":window.rootPath+ '/ui/quote-foreign/getOtherpage',
		                "data": function (d) {
		                    return $.extend({}, d, foreignserverData);
		                }
		            },
		            columns: [ {
						data : null,
						defaultContent : ""
					}, {
						data : 'deviceName'
					}, {
						data : 'type'
					}, 
					{
						data : 'material'
					},
					{
						data : 'unit'
					}, {
						data : 'amount'
					},
					{
						data : 'costPrice'
					},
					{
						data : 'price'
					} ],
		            "drawCallback": function (oSettings) {
		                var k = 0;
		                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
		                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
		                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
		                    k++;
		                }
		            }
				});
   });
	 
	 
